
#include<stdlib.h>

int evalRPN(char** tokens, int tokensSize) {
    int* stack = (int*)malloc(tokensSize * sizeof(int));
    int top = -1;
    int x = 0;
    int y = 0;
    int result;
    for (int i = 0; i < tokensSize; i++) {
        if (tokens[i][0] == '+') {
            x = stack[top--];
            y = stack[top--];
            stack[++top] = x + y;
        }
        else if (tokens[i][0] == '-' && tokens[i][1] == '\0') {
            x = stack[top--];
            y = stack[top--];
            stack[++top] = y - x;
        }
        else if (tokens[i][0] == '*') {
            x = stack[top--];
            y = stack[top--];
            stack[++top] = x * y;
        }
        else if (tokens[i][0] == '/') {
            x = stack[top--];
            y = stack[top--];
            stack[++top] = y / x;
        }
        else {
            stack[++top] = atoi(tokens[i]);
        }

    }
    result = stack[top];
    free(stack);
    return result;
}